package cn.stylefeng.guns.sys.modular.tao.controller;

import cn.stylefeng.guns.sys.modular.api.sdk.Utils;
import cn.stylefeng.guns.sys.modular.tao.entity.Address;
import cn.stylefeng.guns.sys.modular.tao.service.AddressService;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    /**
     * 添加地址
     */
    @RequestMapping("/add")
    public ResponseData addAddress(Address address) {
        if (Utils.checkStringIsNull(address.getProvince(), address.getCity(), address.getDistrict(), address.getDetailAddress(), address.getUserId().toString())) {
            ResponseData.error(500, "参数不能为空");
            return ResponseData.error(500, "参数不能为空");
        }
        ResponseData data = addressService.addAddress(address);
        return data;
    }

    /**
     * 查询地址
     */
    @RequestMapping("/getAddress")
    public ResponseData getAddress(Address address) {
        if (Utils.checkStringIsNull(address.getUserId().toString())) {
            ResponseData.error(500, "参数不能为空");
            return ResponseData.error(500, "参数不能为空");
        }
        ResponseData data = addressService.getAddress(address);
        return data;
    }

    /**
     * 修改地址
     */
    @RequestMapping("/editAdress")
    public ResponseData editAdress(Address address) {
        if (Utils.checkStringIsNull(address.getUserId().toString())) {
            ResponseData.error(500, "参数不能为空");
            return ResponseData.error(500, "参数不能为空");
        }
        ResponseData data = addressService.editAdress(address);
        return data;
    }

    /**
     * 修改是否默认
     */
    @RequestMapping("/editDefault")
    public ResponseData editDefault(Address address) {
        if (Utils.checkStringIsNull(address.getUserId().toString())) {
            ResponseData.error(500, "参数不能为空");
            return ResponseData.error(500, "参数不能为空");
        }
        ResponseData data = addressService.editDefault(address);
        return data;
    }
}
